package com.lingnan.wanxiangxinxun.controller.user;


import com.lingnan.wanxiangxinxun.entity.po.NewsCategory;
import com.lingnan.wanxiangxinxun.entity.vo.common.PageVO;
import com.lingnan.wanxiangxinxun.entity.vo.common.Result;
import com.lingnan.wanxiangxinxun.service.INewsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 新闻分类表 前端控制器
 * </p>
 *
 * @author swl
 * @since 2025-03-13
 */
@RestController("UserNewsCategoryController")
@RequestMapping("/user/news-category")
public class NewsCategoryController {

    @Autowired
    private INewsCategoryService newsCategoryService;

    // 增加新闻分类
    @PostMapping("/add")
    public Result addNewsCategory(@RequestBody NewsCategory newsCategory) {
        newsCategoryService.save(newsCategory);
        return Result.success();
    }


    // 查询所有的新闻分类
    @GetMapping("/getAll")
    public Result getAllNewsCategory() {
        List<NewsCategory> list = newsCategoryService.list();
        return Result.success(list);
    }

    // 分页查询所有的新闻分类
    @GetMapping("/getAllInPage")
    public Result getAllNewsCategoryInPage(@RequestParam(defaultValue = "1") long current,
                                           @RequestParam(defaultValue = "10") long size) {
        PageVO<NewsCategory> vo = newsCategoryService.getAllNewsCategoryInPage(current, size);
        return Result.success(vo);
    }

}
